package br.com.danieljr.crowdmap.modelos;

public class Coordenada {

	private double latitude, longitude;
	public static double NORTE = 0, LESTE = 270, OESTE = 90, SUL = 180;
	public static double radius_km = 6371.0;

	public Coordenada(double latitude, double longitude) {
		this.latitude = latitude;
		this.longitude = longitude;
	}

	public Coordenada() {
	}

	public static Coordenada outraCoordenada(Coordenada c, double distancia, double orientacao) {
		Coordenada resp = new Coordenada();
		orientacao = Math.toRadians(orientacao);
		distancia = distancia / radius_km;
		c.latitude = Math.toRadians(c.latitude);
		c.longitude = Math.toRadians(c.longitude);
		resp.latitude = Math
				.asin(Math.sin(c.latitude) * Math.cos(distancia)
						+ Math.cos(c.latitude) * Math.sin(distancia)
						* Math.cos(orientacao));
		if (Math.cos(resp.latitude) == 0)
			resp.longitude = c.longitude; // endpoint a pole
		else {
			double a = c.longitude
					- Math.asin(Math.sin(orientacao) * Math.sin(distancia)
							/ Math.cos(resp.latitude)) + Math.PI, b = 2 * Math.PI;
			resp.longitude = (a % b) - Math.PI;
		}
		resp.latitude = Math.toDegrees(resp.latitude);
		resp.longitude = Math.toDegrees(resp.longitude);
		return resp;
	}

	public double getLatitude() {
		return latitude;
	}

	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}

	public double getLongitude() {
		return longitude;
	}

	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

}
